package com.wtwd.device.controller;


import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.entity.MedalGroupByVo;
import com.wtwd.device.model.entity.MedalVo;
import com.wtwd.device.model.vo.RespEntity;
import com.wtwd.device.service.MedalService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author mjy
 * @date 2021/09/23
 * @description
 */
@Api(tags = "勋章")
@RestController
@RequestMapping("/app-medal")
public class MedalController {


    @Autowired
    private MedalService medalService;


    private static final Logger logger = LoggerFactory.getLogger(MedalController.class);

    /**
     * 获取所有徽章，标识用户所点亮的徽章
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "获取所有徽章，标识用户所点亮的徽章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "页面大小", required = true, dataType = "Long")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getUserAllMedal")
    public RespEntity<List<MedalGroupByVo>> getUserAllMedal(@RequestParam("userId") Long userId) {
        logger.info("getUserAllMedal param", userId);
        Map<Integer, List<MedalVo>> userAllMedal = medalService.getUserAllMedal(userId);
        ArrayList<MedalGroupByVo> medalGroupByVos = new ArrayList<>();
        Iterator<Map.Entry<Integer, List<MedalVo>>> iterator = userAllMedal.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Integer, List<MedalVo>> next = iterator.next();
            MedalGroupByVo medalGroupByVo = new MedalGroupByVo();
            medalGroupByVo.setType(next.getKey());
            medalGroupByVo.setMedalVos(next.getValue());
            medalGroupByVos.add(medalGroupByVo);
        }
        return new RespEntity(RespCode.SUCCESS, medalGroupByVos);
    }






}
